package org.example.mapreduce.count;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.example.mapreduce.FlowWritable;

import java.io.IOException;

/**
 * @author zhl
 * @version 1.0
 * @ClassName
 * @date 2020/11/12 19:18
 */
public class FlowCountMapper extends Mapper<Object, Text, Text, FlowWritable> {
    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        String[] token = value.toString().replaceAll(" {2,}", " ").split(" ");
        FlowWritable flowWritable = new FlowWritable(token[1], Long.parseLong(token[token.length-3]), Long.parseLong(token[token.length-2]));
        context.write(new Text(token[1]), flowWritable);
    }
}
